
#include "common.h"
#include "uimgr.h"
#include "ControlDef.h"
#include "DNF定义.h"
#include "strid.h"

ImageR_t* EasyGetImageR(int ResId,ImageRType Type/*=IT_Bitmap*/)
{
	if (Type==IT_Bitmap)
		return ResMgr->LoadImageR(GetResId(ResId));
	else if (Type==IT_Scale9)
		return ResMgr->LoadScale9R(GetResId(ResId));
	else if (Type==IT_Animation)
		return ResMgr->LoadAnimationR(GetResId(ResId));
	return NULL;
}

//先设置位置信息，再设置本体信息
int ControlNextX=0;
int ControlNextY=0;
int ControlPageId=0;
UIControl* ControlParent;

void SetCreateControlParam(int X,int Y,UIControl* Parent,int PageId)
{
	ControlNextX=X;
	ControlNextY=Y;
	ControlParent=Parent;
	ControlPageId=PageId;
}

CButton* EasyCreateButton(int CtrlId,int Width,int Height,WCHAR* Text)
{
	CButton* CtrlButton=new CButton(GetCtrlId(CtrlId),ControlNextX,ControlNextY,Width,Height,Text,FALSE);
	UiMgr->InsertControl(ControlPageId,ControlParent,CtrlButton);
	return CtrlButton;
}

CButton* EasyCreateFlatButton(int CtrlId,int Width,int Height,WCHAR* Text)
{
	CButton* CtrlButton=new CButton(GetCtrlId(CtrlId),ControlNextX,ControlNextY,Width,Height,Text,TRUE);
	UiMgr->InsertControl(ControlPageId,ControlParent,CtrlButton);
	return CtrlButton;
}

CImage* EasyCreateImage(int CtrlId,int Width,int Height,int ResId/*=-1*/,ImageRType Type/*=IT_Bitmap*/)
{
	CImage* CtrlImage=new CImage(GetCtrlId(CtrlId),ControlNextX,ControlNextY,Width,Height);
	if (ResId!=-1)
	{
		ImageR_t* ImgRes=EasyGetImageR(ResId,Type);
		CtrlImage->SetImage(ImgRes);
	}
	UiMgr->InsertControl(ControlPageId,ControlParent,CtrlImage);
	return CtrlImage;
}

CLabel* EasyCreateLabel(int CtrlId,int Width,int Height,WCHAR* Text)
{
	CLabel* CtrlLabel=new CLabel(GetCtrlId(CtrlId),ControlNextX,ControlNextY,Width,Height,Text);
	UiMgr->InsertControl(ControlPageId,ControlParent,CtrlLabel);
	return CtrlLabel;
}

CLineLabel* EasyCreateLineLabel(int CtrlId,int Width,int Height,WCHAR* Text)
{
	CLineLabel* CtrlLabel=new CLineLabel(GetCtrlId(CtrlId),ControlNextX,ControlNextY,Width,Height,Text);
	UiMgr->InsertControl(ControlPageId,ControlParent,CtrlLabel);
	return CtrlLabel;
}

CCheckBox* EasyCreateCheckBox(int CtrlId,WCHAR* Text)
{
	CCheckBox* CtrlCheckBox=new CCheckBox(GetCtrlId(CtrlId),ControlNextX,ControlNextY,Text);
	UiMgr->InsertControl(ControlPageId,ControlParent,CtrlCheckBox);
	return CtrlCheckBox;
}

CVScrollView* EasyCreateScrollView(int CtrlId,int Width,int Height,int VirtualHeight)
{
	CVScrollView* CtrlScrollView=new CVScrollView(GetCtrlId(CtrlId),ControlNextX,ControlNextY,Width,Height);
	CtrlScrollView->SetVirtualHeight(VirtualHeight);
	UiMgr->InsertControl(ControlPageId,ControlParent,CtrlScrollView);
	return CtrlScrollView;
}

CEdit* EasyCreateEdit(int CtrlId,int Width)
{
	CEdit* CtrlEdit=new CEdit(GetCtrlId(CtrlId),ControlNextX,ControlNextY,Width);
	UiMgr->InsertControl(ControlPageId,ControlParent,CtrlEdit);
	return CtrlEdit;
}

CSpListBox* EasyCreateSpListBox(int CtrlId,int Width,int Height)
{
	CSpListBox* CtrlSpListBox=new CSpListBox(GetCtrlId(CtrlId),ControlNextX,ControlNextY,Width,Height);
	UiMgr->InsertControl(ControlPageId,ControlParent,CtrlSpListBox);
	return CtrlSpListBox;
}

CDropList* EasyCreateDropList(int CtrlId,int Width,BOOL IconStyle)
{
	CDropList* CtrlDropList=new CDropList(GetCtrlId(CtrlId),ControlNextX,ControlNextY,Width,IconStyle);
	UiMgr->InsertControl(ControlPageId,ControlParent,CtrlDropList);
	return CtrlDropList;
}

CHSlider* EasyCreateSlider(int CtrlId,int Width)
{
	CHSlider* CtrlSlider=new CHSlider(GetCtrlId(CtrlId),ControlNextX,ControlNextY,Width);
	UiMgr->InsertControl(ControlPageId,ControlParent,CtrlSlider);
	return CtrlSlider;
}

CHTabView* EasyCreateTabView(int CtrlId,int Width,int Height)
{
	CHTabView* CtrlTabView=new CHTabView(GetCtrlId(CtrlId),ControlNextX,ControlNextY,Width,Height);
	UiMgr->InsertControl(ControlPageId,ControlParent,CtrlTabView);
	return CtrlTabView;
}